﻿function LoadMoviesByMode(tab, visLang, container){
    if(typeof(tab) == 'undefined' || typeof(container) == 'undefined')
        return;
        
    var is_loaded = $("#" + container).attr("loadcontent");
    if(typeof(is_loaded) != "undefined" && is_loaded == "1")
        return;
        
    //var mode = (tab == "0"?"NowShowing":(tab == "1"?"ComingSoon":"TetMovies"));
	var mode = "";
	switch(tab){
		case 0:
			mode = "NowShowing";
			break;
		case 1:
			mode = "ComingSoon";
			break;
		case 2:
			//mode = "TetMovies";
			mode = "MegaStarPicks";
			
			break;
		case 3:
			mode = "MegaStarPicks";
			break;
	}
    var XMLpath ="/megastarXMLData.aspx?RequestType=GetMovieListByMode&&visMode=" + mode + "&&visLang=" + gLang;
    $.get(XMLpath,{},function(xml){
        var html = '<div class="tab-loop-bg"><div id="' + container + '_croll" class="flexcroll film-pane">';
        html += '<table border="0" cellpadding="0" cellspacing="0"><tr>';
        
        var count = 0;
        $('movie',xml).each(function(i) {
            var MovieId = $(this).find("MovieId").text();
			var MovieName = $(this).find("MovieName").text();
			var MovieNameShort = $(this).find("MovieNameShort").text();
			var ImageUrlSmall = $(this).find("ImageUrlSmall").text();
			var ImageUrlLarge = $(this).find("ImageUrlLarge").text();
			var MovieNameVar = addslashes($(this).find("MovieNameVar").text());
			var Trailer = $(this).find("Trailer").text();
			var MovieInfoUrl = $(this).find("MovieInfoUrl").text();
			var Award = $(this).find("Award").text();
			var ShortDesc = $(this).find("ShortDesc").text();
			var FriendlyName = $(this).find("FriendlyName").text();
			var TrailerShow = $(this).find("TrailerShow").text();
			var YoutubeUrl = $(this).find("YoutubeUrl").text();
			var Microsite = $(this).find("Microsite").text();
			var YoutubeID = "";
			if(YoutubeUrl != ""){
				YoutubeID = YoutubeUrl.substring(YoutubeUrl.indexOf("="), YoutubeUrl.length);
				YoutubeID = YoutubeID.replace("=", "");
			}
			
			html += '  <td valign="top">';
			html += '  <div class="col_film">';
			html += '  <div class="trailer_vis" title="' + MovieName  + '" trailer="' + Trailer + '" trailer_show="' + TrailerShow + '" youtube_id="' + YoutubeID + '"><a href="#"></a></div>';
			html += '      <a class="film_imt" href="/' + (visLang == "1"?"vn": "en") + "/" + FriendlyName + '"><img width="130" src="' + ImageUrlLarge + '" alt="" /></a>';
            html += '      <div class="film_tit">' + MovieName + '</div>';
           	html += '      <div style="padding-top: 3px">';
			/*if(FriendlyName == '3d-megamind' || FriendlyName == 'megamind')
			{
				html += '          <a href="/megamind/" target="_blank" class="viewmore-btn' + (visLang == "1"?"_vn":"") + '" ></a>';
			}
			else if(FriendlyName == '3d-tron-legacy' || FriendlyName == 'tron-legacy'){
				html += '          <a href="/tron' + (visLang == "1"?"":"-en") + '" target="_blank" class="viewmore-btn' + (visLang == "1"?"_vn":"") + '" ></a>';
			}
			else
			{
				html += '          <a href="/' + (visLang == "1"?"vn": "en") + "/" + FriendlyName + '" class="viewmore-btn' + (visLang == "1"?"_vn":"") + '" ></a>';
			}*/
			html += '          <a href="/' + (visLang == "1"?"vn": "en") + "/sessiontimes/" + FriendlyName + '" class="buyticket-btn' + (visLang == "1"?"_vn":"") + '"></a>';
			if(Microsite != "" && Microsite.indexOf("/") != -1){
				html += '          <a href="' + Microsite + '" target="_blank" class="viewmore-btn' + (visLang == "1"?"_vn":"") + '" ></a>';
			}else{
				html += '          <a href="/' + (visLang == "1"?"vn": "en") + "/" + FriendlyName + '" class="viewmore-btn' + (visLang == "1"?"_vn":"") + '" ></a>';
			}
			
            
            html += '          <div style="clear: both"></div>';
            html += '      </div>';
			html += '  </div>';
			html += '  </td>';
			count ++;
        });
        html += '</tr></table>';
        html += '</div></div>';
        $("#" + container).html(html);
        $("#" + container).attr("loadcontent", "1");
        //fleXenv.initByClass("flexcroll");
		fleXenv.fleXcrollMain(container + '_croll');
		$("div.trailer_vis").fadeTo("fast", 0.0);
		$('div.col_film').mouseover(function() {
			var item_trailershow = $(this).children("div.trailer_vis").attr("trailer_show");
			
			if(item_trailershow == '1' && $(this).children("div.trailer_vis").attr("trailer") != 'undefined' && $(this).children("div.trailer_vis").attr("trailer") != ""){
				var trailer = $(this).children("div.trailer_vis").attr("trailer");				
				$(this).children("div.trailer_vis").addClass("overlay-trailer");
				$(this).children("div.trailer_vis").stop().fadeTo(400, 0.85);
				$(this).children("div.overlay-trailer").click(function(){
					play_trailer(trailer);
				});
			}
			
			if(item_trailershow == '2' && $(this).children("div.trailer_vis").attr("youtube_id") != 'undefined' && $(this).children("div.trailer_vis").attr("youtube_id") != ""){
				var youtubeid = $(this).children("div.trailer_vis").attr("youtube_id");
				//var movie_title = $(this).children("div.film_tit").html();
				var movie_title = $(this).children("div.trailer_vis").attr("title");
				
				$(this).children("div.trailer_vis").addClass("overlay-trailer");
				$(this).children("div.trailer_vis").stop().fadeTo(400, 0.85);
				$(this).children("div.overlay-trailer").click(function(){
					play_trailer('',youtubeid, movie_title);
				});
			}
		}).mouseout(function() {
			$(this).children("div.trailer_vis").stop().fadeTo(200, 0);
			$(this).children("div.trailer_vis").removeClass("overlay-trailer");
		});
		//$("#" + container + "_croll_contentwrapper div.film-pane-2").css("width", (135 * count));
    }, "xml");
}
		
function LoadOffersByMode(tab, visLang, container){
    if(typeof(tab) == 'undefined' || typeof(container) == 'undefined')
        return;

    var is_loaded = $("#" + container).attr("loadcontent");
    if(typeof(is_loaded) != "undefined" && is_loaded == "1"){
		return;
    }
        
    var lang = visLang == "1"?"vn":"en";
    var XMLpath ="/xml/main-display.xml";
    $.get(XMLpath,{},function(xml){
        var html = '<div id="' + container + '-spotlight" class="spotlight"><ul>';
        var count = 0;
        $("tab-" + (tab + 1), xml).find(lang).find('item').each(function(){
            var offer_name = $(this).find('name').text();
            var image = $(this).find('image').text();
            var desc = $(this).find('desc').text();
			var url = $(this).find('url').text();
            html += '<li>';
			
			if(url.indexOf("/") != -1){
				html += '<a href="' + url + '">';
			}else{
				html += '<a href="javascript:void(0)" onclick="' + url + '">';
			}
			
			if(count == 0)
				html += '<img src="'+ image +'" /></a>'; 
			else
				html += '<img src="/images/loading.gif" desc="' + image + '"/></a>'; 
            html += '   <div class="panel-overlay">';  
            html += 	offer_name; 
            html += '       <p>' + desc + '</p> '; 
            html += '   </div>'; 
            html += '</li>';
            count++;
        });
        html += '</ul>';
        html += '</div>';
        $("#" + container).html(html);
        $("#" + container).attr("loadcontent", "1");
        $("#" + container +"-spotlight").easySlider({
			auto: true,
			speed: 		800,
			pause:			5000,
			continuous: true,
			numeric: 		true,
			numericId: 		container + '-controls'
		});
    });
}

function LoadTopComments(visLang, container){
    if(typeof(container) == 'undefined')
        return;

    var is_loaded = $("#" + container).attr("loadcontent");
    if(typeof(is_loaded) != "undefined" && is_loaded == "1"){
		return;
    }
    
    var XMLpath ="/megastarXMLData.aspx?RequestType=GetTopMemberComments&&top=9&&visLang=" + gLang;
    $.get(XMLpath,{},function(xml){
		var html = '';
        var count = 0;
        
        $('item',xml).each(function(i) {
            var movie_name = $(this).find("movie").text();
            var friendly_name = $(this).find("friendly_name").text();
            var comment = $(this).find("comment").text();
            var postby = $(this).find("postby").text();
            var postdate = $(this).find("postdate").text();
            
			if(count %2 == 0)
            	html += "<div class=\"row-1\">";
			else
				html += "<div class=\"row-1-2\">";
            if (friendly_name != "")
            {
                html += "   <a href=\"/" + (visLang == "1" ? "vn" : "en") + "/" + friendly_name + "#list_comments\">" + movie_name + "</a> - " + postby + "<br />";
            }
            else
            {
                html += "   <a href=\"#\">" + movie_name + "</a> - " + postby + "<br />";
                
            }
            html += "   <em>\" " + comment;
            html += "\"</em></div>";
            
            count++;
        });
        
        $("#" + container).html(html);
        $("#" + container).attr("loadcontent", "1");
        $("#" + container).jScrollPane({showArrows:true,scrollbarWidth:15});
    });
}

function LoadWinnersNotifications(visLang, container){
	var is_loaded = $("#" + container).attr("loadcontent");
    if(typeof(is_loaded) != "undefined" && is_loaded == "1")
        return true;
	
	var XMLpath ="/megastarInternalXMLData.aspx?RequestType=WinnersNotifications&visLang=" + visLang;
    $.get(XMLpath,{},function(xml){
		var html = '<div class="winner_col">\n';
        var count = 0;
        var step = 0;
        
        $('Promo',xml).each(function(i) {
            var promo_name = $(this).find("Name").text();
            var from_date = $(this).find("Fromdate").text();
            var to_date = $(this).find("Todate").text();
            html += '<div class="contest_title">' + promo_name + '</div>\n';
			html += '<div class="contest_time">' + (visLang == "1" ? "Th&#7901;i gian: " : "Contest Time: ") +  from_date + " - " + to_date + '</div>\n';
			html += '<table width="100%" border="0" cellpadding="0" cellspacing="0">\n';
			html += '<tr class="contest_tb_header">\n';
            html += '<td width="76">' + (visLang == "1" ? "STT" : "Winner's List") + '</td>\n';
            html += '<td width="154">' + (visLang == "1" ? "Gi&#7843;i th&#432;&#7903;ng" : "Item") + '</td>\n';
            html += '<td width="188">' + (visLang == "1" ? "T&#234;n" : "Name") + '</td>\n';
            html += '<td width="157">' + (visLang == "1" ? "&#272;&#7883;a ch&#7881;" : "City") + '</td>\n';
            html += '</tr>\n';
			$(this).find("Item").each(function(e){
				count ++;
				var price = $(this).find("Price").text();
				var province = $(this).find("Province").text();
				var full_name = $(this).find("FullName").text();
				html += '<tr>\n';
                html += '	<td align="center">' + count + '</td>\n';
                html += '    <td align="center">' + price + '</td>\n';
                html += '    <td align="center">' + full_name + '</td>\n';
                html += '    <td align="center">' + province + '</td>\n';
                html += '</tr>\n';
			});
			html += '</table>\n';
        });
        html += '</div>\n';
        
        $("#" + container).html(html);
        $("#" + container).attr("loadcontent", "1");
    });
}